package sdk.webview.fmc.com.fmcsdk.view;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import sdk.webview.fmc.com.fmcsdk.R;
import sdk.webview.fmc.com.fmcsdk.activity.NotifySettingActivity;
import sdk.webview.fmc.com.fmcsdk.activity.SettingGuideActivity;
import sdk.webview.fmc.com.fmcsdk.bean.SystemSetting;
import sdk.webview.fmc.com.fmcsdk.util.Constant;
import sdk.webview.fmc.com.fmcsdk.util.PreferencesHelper;
import sdk.webview.fmc.com.fmcsdk.util.ToastUtils;

public class NoticeTipsDialog extends Dialog {
    private Context context;
    private boolean isCheck = false;

    //只有提示内容的消息框
    public NoticeTipsDialog(Context context) {
        super(context, R.style.Dialog);
        this.context = context;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.notice_tips_dialog);
        final ImageView checkBox = (ImageView) findViewById(R.id.cb_check);

        findViewById(R.id.ll_check).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                isCheck = !isCheck;
                checkBox.setBackgroundResource(isCheck==true?R.mipmap.check2:R.mipmap.check1);
            }
        });


       findViewById(R.id.confirm).setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
               if (isCheck) {
                   PreferenceManager.getDefaultSharedPreferences(context).edit().putString(Constant.FIRST_NOTICE, "noFirstNotice").apply();
               }
               dismiss();
           }
       });

       findViewById(R.id.tv_setting).setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {

               SystemSetting systemSetting = PreferencesHelper.getData(SystemSetting.class);
               if (systemSetting==null){
                   ToastUtils.showShort(context,context.getResources().getString(R.string.pls_call_admin));
                   return;
               }
               if (TextUtils.isEmpty(systemSetting.getRecord().getAPP_VOICE_SIZE())){
                   ToastUtils.showShort(context,context.getResources().getString(R.string.pls_call_admin));
                   return;
               }
               Intent intent = new Intent(context, SettingGuideActivity.class);
               intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
               intent.putExtra("url",systemSetting.getRecord().getAPP_VOICE_SIZE());
               context.startActivity(intent);
           }
       });
        //试着提示框的位置和大小
        Window dialogWindow = getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        DisplayMetrics d = context.getResources().getDisplayMetrics(); // 获取屏幕宽、高
        lp.width = (int) (d.widthPixels * 0.9);
        dialogWindow.setAttributes(lp);

    }

}

